<?php

namespace App\Observers;

use App\Models\Community;
use App\server\RedisServer;
class CommunityObserver
{
    /**
     * Handle the Community "created" event.
     *
     * @param  \App\Models\Community  $community
     * @return void
     */
    public function created(Community $community)
    {
        //
        $redis=RedisServer::createRedisObject();
        $redis->select(10);
        $communitydata=$community->toArray();
        $redis->hSetone($communitydata);
    }

    /**
     * Handle the Community "updated" event.
     *
     * @param  \App\Models\Community  $community
     * @return void
     */
    public function updated(Community $community)
    {
        //
        $data=$community->toArray();
        $redis=RedisServer::createRedisObject();
        $redis->select(10);
        foreach ($data as $key => $value){
            $redis->hset($data['id'],$key,$value);
        }
    }

    /**
     * Handle the Community "deleted" event.
     *
     * @param  \App\Models\Community  $community
     * @return void
     */
    public function deleted(Community $community)
    {
        //
    }

    /**
     * Handle the Community "restored" event.
     *
     * @param  \App\Models\Community  $community
     * @return void
     */
    public function restored(Community $community)
    {
        //
    }

    /**
     * Handle the Community "force deleted" event.
     *
     * @param  \App\Models\Community  $community
     * @return void
     */
    public function forceDeleted(Community $community)
    {
        //
    }
}
